package orderoid.soap.business;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.AsyncTask;
import android.util.Log;

public class webServiceCommande extends AsyncTask<String, Void, Boolean> {

	private static final String PARAM_MENUS = "menus";
	private static final String PARAM_PRODUITS = "produits";
	private static final String PARAM_IDADRESSE = "idAdresse";
	private static final String PARAM_IDCLIENT = "idClient";
	private static final String PARAM_IDRESTAURANT = "idRestaurant";
	
	@Override
	protected Boolean doInBackground(String... params) {
		Log.e("Test", "doInBackground : WebService Commande");
		
		String menus = params[0];
    	String produits = params[1];
    	String idAdresse = params[2];
    	String idClient = params[3];
    	String idRestaurant = params[4];
    	
		SoapObject request = new SoapObject(
				orderoid.soap.constant.method.NAMESPACE,
				orderoid.soap.constant.method.METHOD_NAME_COMMANDER);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);

		envelope.setOutputSoapObject(request);

		HttpTransportSE androidHttpTransport = new HttpTransportSE(
				orderoid.soap.constant.method.URL);

		request.addProperty(PARAM_MENUS, menus);
		request.addProperty(PARAM_PRODUITS, produits);
		request.addProperty(PARAM_IDADRESSE, idAdresse);
		request.addProperty(PARAM_IDCLIENT, idClient);
		request.addProperty(PARAM_IDRESTAURANT, idRestaurant);

		Boolean validCommande = false;
		try {
			androidHttpTransport.call(
					orderoid.soap.constant.method.SOAP_ACTION_COMMANDER,
					envelope);
		
			SoapPrimitive soapObjectResp = (SoapPrimitive) envelope.getResponse();
			validCommande = Boolean.valueOf(soapObjectResp.toString());
		
		} catch (Exception e) {
			Log.e("Erreur", e.getMessage());
		}
		return validCommande;
	}

}
